package com.example.security.exception;

import com.example.security.VO.ResultVO;
import com.example.security.utils.ResultUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MyExceptionHandler {

    @ResponseBody
    @ExceptionHandler(MyException.class)
    public ResultVO handleException(Exception e){
        if(e instanceof MyException) {
            return ResultUtil.error(((MyException)e).getCode(), e.getMessage());
        }else {
            return ResultUtil.error(500,e.getMessage());
        }
    }
}
